<template>
  <div>
    <div>
      <van-search v-model="value" placeholder="请输入搜索关键词" />
    </div>
    <!-- 侧边导航 -->
    <van-sidebar v-model="activeKey">
      <van-sidebar-item title="所有分类" @click="classList1" />
      <van-sidebar-item title="居家" @click="classList2" />
      <van-sidebar-item title="配件装饰" @click="classList3" />
      <van-sidebar-item title="服饰" @click="classList4" />
      <van-sidebar-item title="电器" @click="classList5" />
    </van-sidebar>
    <!-- 轮播 -->
    <div class="Classify_swiper">
      <van-swipe
        class="my-swipe"
        :autoplay="3000"
        indicator-color="white"
        style="height: 4.2rem"
      >
        <van-swipe-item v-for="(item, index) in getSwiper" :key="index">
          <img :src="item.picUrl" alt="" />
        </van-swipe-item>
      </van-swipe>
      <Classlist :lsit="Classlist"></Classlist>
    </div>
  </div>
</template>

<script>
import Classlist from "./Classlist";
export default {
  data() {
    return {
      value: "",
      activeKey: 0,
      getSwiper: [],
      lsit: [],
      Classlist: [],
    };
  },
  components: {
    Classlist,
  },
  mounted() {
    this.$API.getSwiper().then((res) => {
      console.log(res);
      this.getSwiper = res.data.data;
    });
    this.$API.getClassList().then((res) => {
      console.log(res);
      this.lsit = res.data.data;
      this.Classlist = res.data.data;
    });
  },
  methods: {
    classList1() {
      this.Classlist = this.lsit;
    },
    classList2() {
      this.Classlist = [];
      this.lsit.forEach((element) => {
        if (element.type == "jujia2") {
          this.Classlist.push(element);
        }
      });
      this.Classlist = this.Classlist;
    },
    classList3() {
      this.Classlist = [];
      this.lsit.forEach((element) => {
        if (element.type == "peishi2") {
          this.Classlist.push(element);
        }
      });
      this.Classlist = this.Classlist;
    },
    classList4() {
      this.Classlist = [];
      this.lsit.forEach((element) => {
        if (element.type == "fuzhuang2") {
          this.Classlist.push(element);
        }
      });
      this.Classlist = this.Classlist;
    },
    classList5() {
      this.Classlist = [];
      this.lsit.forEach((element) => {
        if (element.type == "dianqi2") {
          this.Classlist.push(element);
        }
      });
      this.Classlist = this.Classlist;
    },
  },
};
</script>

<style lang="scss">
.van-search {
  position: fixed;
  top: 0;
  z-index: 99999999999;
  width: 100%;
}
.van-sidebar {
  width: 2rem;
  margin-top: 1rem;
  position: fixed;
  left: 0;
}
.Classify_swiper {
  float: right;
  width: 75%;
  height: 2.4rem;
  .van-swipe-item {
    width: 70%;
    height: 50%;
    color: #fff;
    font-size: 20px;
    height: 3.5rem;
    text-align: center;
    background-color: white;
    margin-top: 1rem;
    img {
      width: 100%;
      height: 100%;
      border-radius: 0.2rem;
    }
  }
}
</style>